class Solution:
    def numRookCaptures(self, board: List[List[str]]) -> int:
        # 找出车'R'
        for i in range(8):
            for j in range(8):
                if board[i][j] == 'R':
                    x, y = i, j
        # 统计数量
        cnt = 0

        # 重写了dx, dy的方向向量
        for dx, dy in [(1,0), (-1,0), (0,1), (0,-1)]:
            step = 0
            while True:
                x_t = x + step*dx
                y_t = y + step*dy
                # 当棋子越界或检测位置为白象'B'，当前方向无法找到可吃的棋子
                if x_t <0 or x_t >=8 or y_t < 0 or y_t >= 8 or board[x_t][y_t] == 'B':
                    break
                elif board[x_t][y_t] == 'p':
                    cnt += 1
                    break
                step += 1
        return cnt

if __name__ == '__main__':
    s = Solution()
    print(s.numRookCaptures([[".",".",".",".",".",".",".","."],[".",".",".","p",".",".",".","."],[".",".",".","R",".",".",".","p"],[".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".","."],[".",".",".","p",".",".",".","."],[".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".","."]]))
    print(s.numRookCaptures([[".",".",".",".",".",".",".","."],[".","p","p","p","p","p",".","."],[".","p","p","B","p","p",".","."],[".","p","B","R","B","p",".","."],[".","p","p","B","p","p",".","."],[".","p","p","p","p","p",".","."],[".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".","."]]))
    print(s.numRookCaptures([[".",".",".",".",".",".",".","."],[".",".",".","p",".",".",".","."],[".",".",".","p",".",".",".","."],["p","p",".","R",".","p","B","."],[".",".",".",".",".",".",".","."],[".",".",".","B",".",".",".","."],[".",".",".","p",".",".",".","."],[".",".",".",".",".",".",".","."]]))